package main

import (
    "flag"
    "log"
    "os"
    "runtime"

    "go-gateworker/internal/config"
    "go-gateworker/internal/master"
)

func main() {
    // 命令行参数
    configFile := flag.String("config", "", "配置文件路径")
    numWorkers := flag.Int("workers", runtime.NumCPU(), "Worker进程数量")
    flag.Parse()

    // 加载配置
    cfg, err := config.LoadConfig(*configFile)
    if err != nil {
        log.Fatalf("Failed to load config: %v", err)
    }

    // 如果指定了worker数量，覆盖配置
    if *numWorkers > 0 {
        cfg.NumWorkers = *numWorkers
    }

    // 创建并启动master
    m := master.New(cfg)
    if err := m.Start(); err != nil {
        log.Fatal(err)
    }
}